package com.android.duininsuoai.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.duininsuoai.R;
import com.android.duininsuoai.activity.BaseObject;
import com.android.duininsuoai.model.member.AddressAreaData;
import com.android.duininsuoai.utils.GlideCircleTransform;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/9/6.
 */

public class AddressPop extends PopupWindow {
    private PopupWindow popupWindow;
    private Activity context;
    private String message;
    private String avatar;
    private int id;
    private View view;
    private ArrayList<AddressAreaData.DataBean> addressdata;
    public AddressPop(Activity context, String message, String avatar, int id) {
        super(context);
        this.message = message;
        this.avatar = avatar;
        this.id = id;
        this.context = context;
        init(context);
    }
    private void init(final Context context) {
        view = LayoutInflater.from(context).inflate(R.layout.toast, null);
        ImageView toastpic = (ImageView) view.findViewById(R.id.toastpic);
        Glide.with(context).load(avatar)
                .transform(new GlideCircleTransform(context))
                .into(toastpic);
        TextView toasttext = (TextView) view.findViewById(R.id.toasttext);
        toasttext.setText(message);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_tuan = new Intent(context, BaseObject.class);
                intent_tuan.putExtra("title", "团详情");
                intent_tuan.putExtra("need_id", id + "");
                context.startActivity(intent_tuan);

            }
        });

        popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);


    }

    public void show() {

        popupWindow.update();
        popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.LEFT | Gravity.TOP, 30, 300);

    }

    public void dismiss() {
        popupWindow.dismiss();

    }


}
